package com.eastfair.visitor.controller;

import com.eastfair.visitor.dto.*;
import com.eastfair.visitor.entity.Reservation;
import com.eastfair.visitor.service.ReservationService;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.eastfair.boot.controller.SuperController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eastfair.echo.core.EchoService;
import com.eastfair.core.base.R;
import com.eastfair.visitor.vo.DepartmentVO;
import com.eastfair.visitor.vo.ReservationVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import com.eastfair.annotation.annotation.security.PreAuth;

import com.eastfair.boot.request.PageParams;
import com.eastfair.core.context.ContextUtil;
import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 前端控制器
 * 访客预约
 * </p>
 *
 * @author lyw
 * @date 2022-11-18
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/reservation")
@Api(value = "Reservation", tags = "访客预约")
@PreAuth(replace = "visitor:reservation:")
public class ReservationController extends SuperController<ReservationService, Long, Reservation, ReservationPageQuery, ReservationSaveDTO, ReservationUpdateDTO> {

    @Autowired
    private EchoService echoService;
    @Autowired
    private ReservationService reservationService;

    @Override
    public void handlerResult(IPage<Reservation> page) {
        // 想让返回值实现自动回显，请将此行代码打开
        // echoService.action(page);
    }
    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list){
        List<Reservation> reservationList = list.stream().map((map) -> {
            Reservation reservation = Reservation.builder().build();
            //TODO 请在这里完成转换
            return reservation;
        }).collect(Collectors.toList());

        return R.success(baseService.saveBatch(reservationList));
    }



    /**
     * 处理参数
     *
     * @param params 分页参数
     */
    @Override
    public void handlerQueryParams(PageParams<ReservationPageQuery> params) {
        ReservationPageQuery pageQuery = params.getModel();

    }





    /**
     * 添加访客预约信息
     * @param reservationSaveDTO
     * @return
     */
    @ApiOperation(value = "添加访客预约信息")
    @PostMapping(value = "/saveReservationInfo")
    public R<Boolean> saveReservationInfo (@RequestBody ReservationSaveDTO reservationSaveDTO) {

        return R.success(reservationService.saveReservationInfo(reservationSaveDTO));
    }


    /**
     * 通过id查询访客信息
     *
     * @return
     */
    @ApiOperation(value = "通过id查询访客信息")
    @PostMapping(value = "/getReservationInfoById")
    public R<ReservationVO> getReservationInfoById(@RequestBody ReservationDTO reservationDTO) {
        return R.success(reservationService.getReservationInfoById(reservationDTO));
    }


}
